package com.lly.songhigh.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lly.songhigh.R;
import com.lly.songhigh.entity.AlbumDetials;

import java.util.List;

/**
 * Created by 李海龙 on 15/11/3.
 */
public class AlbumDetialsDownloadAdapter extends BaseAdapter {

    private long size;
    private long zhenSize;
    private Context context;
    private List<AlbumDetials.AuditionListEntity> auditionListEntities;

    public AlbumDetialsDownloadAdapter(List<AlbumDetials.AuditionListEntity> auditionListEntities, Context context) {
        this.auditionListEntities = auditionListEntities;
        this.context = context;
    }

    @Override
    public int getCount() {
        return auditionListEntities != null && auditionListEntities.size() > 0 ? auditionListEntities.size() : 0;
    }

    @Override
    public AlbumDetials.AuditionListEntity getItem(int position) {
        return auditionListEntities.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.chatrs_download_listview_item, null);
            holder = new ViewHolder();
            holder.song_size = (TextView) convertView.findViewById(R.id.charts_download_size);
            holder.songQuality = (TextView) convertView.findViewById(R.id.charts_download_quality);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        AlbumDetials.AuditionListEntity listEntity = getItem(position);
        size = listEntity.getSize()/1024000;
        zhenSize = listEntity.getSize() / 10240%100;
        holder.songQuality.setText(listEntity.getTypeDescription());
        holder.song_size.setText(size + "." + zhenSize + "M");
        return convertView;
    }

    private class ViewHolder{

        private TextView songQuality, song_size;
    }
}
